import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author: zhangxupeng
 * @date:2019/5/10
 * @Email: zhangxupeng@bilibili.com
 **/
public class TestArrayToStream {
    public static void main(String[] args) {
        //对象数组
        String[] array = {"a", "b", "c", "d", "e"};

        //Arrays.stream
        Stream<String> stream1 = Arrays.stream(array);
        stream1.forEach(System.out::println);

        //原始数组
        int[] intArray = {1, 2, 3, 4, 5};


        {
            //推荐
            IntStream intArrayStream = Arrays.stream(intArray);
            intArrayStream.forEach(System.out::println);
        }

        {
            //不推荐
            Stream<int[]> temp = Stream.of(intArray);
            IntStream intStream2 = temp.flatMapToInt(Arrays::stream);
            intStream2.forEach(System.out::println);
        }



        //对于对象数组，都会调用Arrays.stream。 对于原始数组，更推荐Arrays.stream，因为它直接返回固定大小的IntStream，更易于操作。
    }
}
